package com.huangliusong.quickstart;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author huangliusong
 * @since 2018/11/25
 * {@link }
 */
public class Producter {
    public static void main(String[] args) throws IOException, TimeoutException {
        //创建一个连接工厂
        ConnectionFactory connectionFactory=new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("admin");
        connectionFactory.setPassword("admin");
        connectionFactory.setVirtualHost("/");
        //创建连接通过工厂
        Connection connection=connectionFactory.newConnection();
        //通过conection创建一个channel
        Channel channel=connection.createChannel();
        //通过channel发送数据
        for (int i=0;i<600;i++){
            String message="你好这个一个消息 "+i;
            channel.basicPublish("","test001",null,message.getBytes());
            System.out.println(i);
        }
        //关闭相关到连接
        channel.close();
        connection.close();
    }
}
